<template>
  <!-- 回复(上报方案人)业务待办 -->
  <a-spin :spinning="loading">
  <div :class="resolveInfo?'':'wrapper'">
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <title-name title="处理" v-if="!resolveInfo"/>
      <div v-for="item in replyQueryTable" :key="item.id">
        <title-name style="margin-left: 30px">回复<span style="color:#1890ff">{{item.nodeName}}</span>信息</title-name>
        <a-form-model ref="ruleForm" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }" :rules="rules">
          <a-row :gutter="24">
            <a-col :md="24" :sm="24">
              <a-form-model-item class="formTable">
                <a-table ref="formTable" bordered :columns="columns" :data-source="item.opinionDTOList" :pagination="false">
                  <template v-for="col in ['opinion', 'opinionReply']" :slot="col" slot-scope="text, record">
                    <div :key="col" class="form-item">
                      <template>
                        <BaseInput v-if="col === 'opinionReply'" v-model="record[col]" :disabled="resolveInfo"></BaseInput>
                        <span v-else>{{ record[col] }}</span>
                      </template>
                    </div></template
                  >
                </a-table>
              </a-form-model-item>
              <a-col :md="24" :sm="24">
                <a-form-model-item label="附件上传">
                  <upload-list :business-code="'TM05'" :upload-arrys.sync="item.fileInfoVOS" multiple  :disabled="resolveInfo"/>
                </a-form-model-item>
              </a-col>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <a-button :loading="loading" class="ml12" type="primary" @click="submit" v-if="!resolveInfo"> 确定处理 </a-button>
      <a-button v-else class="ml12" type="primary" @click="handleClose()">关闭</a-button>
    </div>
  </div>
  </a-spin>
</template>
  <script>
import UploadList from '@/components/UploadList'
import { getReplyAuditApproval,replyAuditApproval} from '@/api/technical/approval'
import { finishBusinessTodo } from '@/api/commons.js'
import moment from 'moment'
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    align: 'center',
    customRender() {
      return arguments[2] + 1
    }
  },
  { title: '修改意见', align: 'center', dataIndex: 'opinion', scopedSlots: { customRender: 'opinion' },width: 500,},
  { title: '回复信息', dataIndex: 'opinionReply', align: 'center', scopedSlots: { customRender: 'opinionReply' } }
]
export default {
  name: 'promoteExcellence',
  props: {
    id: {
      //推优详情数据
      type: String,
      default: ''
    },
    resolveInfo:{
      type: Boolean,
      default: false
    }
  },
  components: {
    UploadList
  },
  data() {
    return {
      columns,
      form: {
        tableData: [{ content: null }],
        fileInfoVOList: [],
      },
      loading:false,
      rules: {
        programTypeId: [{ required: true, message: '请选择', trigger: 'change' }],
        value: [{ required: true, message: '请选择', trigger: 'change' }]
      },
      replyQuery: {}, //查询回复信息
      replyQueryTable:[],
    }
  },
  mounted() {
    this.getReplyAuditApprovalFn()
  },
  methods: {
    getReplyAuditApprovalFn() {
      this.loading = true;
      getReplyAuditApproval({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.loading = false;
          this.replyQuery = res.data
          this.replyQueryTable = this.replyQuery.auditApprovalDTOS || [];
          this.$emit('transfer',this.replyQuery.constructionProgramId);  //用这个id来查询详情信息
        }
      })
    },
    handleClose() {
      this.$multiTab.close(this.$route.fullpath)
    },
    submit() {
      let childData = [],
      opinionDTOList = [];
      this.replyQueryTable.map((item)=>{
        let flag = item.opinionDTOList.every((cItem)=>cItem.opinionReply);
        flag && childData.push(flag)
        opinionDTOList.push(item)
      })
      if(opinionDTOList.length != childData.length){   //长度不一样，证明存在没有填写完成
        this.$message.warning('请填写完成回复信息');
        return 
      }
      this.replyQuery.replyDate = moment().format('YYYY-MM-DD');
      this.replyQuery.replyStatus = 1;
      this.loading = true;
      replyAuditApproval(this.replyQuery).then((res)=>{
        if(res.code == 200){
          finishBusinessTodo({ id: this.$route.query.messageId }).then((res1) => {
            if (res1.code !== '0') {
              return
            }
          })
          this.$message.success('处理成功')
          this.loading = false;
          this.$close()
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.wrapper {
  @{deep} .ant-input {
    border-color: #e4ac0b;
    background-color: #fff9e8;
  }
  @{deep} .ant-form-item .ant-form-item-label {
    width: 74px;
  }
  .formTable {
    @{deep} .ant-form-item-control-wrapper {
      width: 100%;
    }
  }
}
</style>
  